<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>create</title>
  </head>
  <body></body>
</html>
<script>
  /**
   *
   * 创建新对象并为其指定一个原型。
   * 它的作用类似于构造函数的new关键字；
   * 不需要显式地指明构造函数，而是直接基于现有的对象作为新对象的原型
   */

  const parent = {
    name: "zhangsan",
    age: 18,
  };
  // 必须是实例对象
  const oc = Object.create(parent); // 原型指向 obj
  console.log(oc.__proto__ === parent); // true
  console.log(oc); // zhangsan
  console.log(parent);
  console.log("___________________________________________");

  // 没有原型
  const oc2 = Object.create(null, {
    customProp: {
      value: "Custom Value",
      writable: false, // 可写
      configurable: false, // 可配置
      enumerable: false, // 可枚举
    },
  });
  oc2.customProp = "123"; // 不可写
  console.log(oc2);
  console.log(oc2.__proto__);
  console.log("___________________________________________");

  // 类
  class Person {
    static age = 20;
    constructor() {
      this.state = {
        name: "lisi",
      };
    }
    sayName() {
      console.log(this.state.name);
    }
    static sayAge() {
      console.log(this.age);
    }
  }
  const p = new Person();
  console.log(p);
  const oc3 = Object.create(p);
  console.log(oc3);
</script>
